package com.gitee.wsl.compose.chart.polar.axis

import com.gitee.wsl.common.ui.api.LabelAble
import com.gitee.wsl.unit.angle.AngleUnit
import com.gitee.wsl.unit.angle.PolarAngleDirection
import com.gitee.wsl.unit.angle.PolarAngleZero
import com.gitee.wsl.unit.angle.originOffset
import com.gitee.wsl.unit.angle.toRadians

/**
 * An interface for classes representing the angular axis on a polar plot.
 *
 * @param T The data type for the axis values.
 */
 interface AngularAxisModel<T> : LabelAble<T> {

    /**
     * Gets the tick values for this axis model.
     */
     fun getTickValues(): List<T>

    /**
     * Computes the angular offset of the provided point along this axis.
     * This function provides a mechanism to transform from arbitrary units [T] to angular units on the plot.
     * For example, a category axis can convert specific categories to
     * their angular position on the plot.
     */
     fun computeOffset(point: T): AngleUnit

    /**
     * The [PolarAngleDirection] for this axis.
     */
     val polarAngleDirection: PolarAngleDirection

    /**
     * The [PolarAngleZero] for this axis.
     */
     val polarAngleZero: PolarAngleZero

     companion object
}

/**
 * Transforms [inputAngle] based on the [AngularAxisModel] settings to be in the coordinate system of the screen where
 * 0-degrees is at the 3 O'Clock position and angles increment clockwise.
 */
fun <T> AngularAxisModel<T>.toPolarAngle(inputAngle: AngleUnit): AngleUnit {
    val sign = if (polarAngleDirection == PolarAngleDirection.CLOCKWISE) {
        1.0
    } else {
        -1.0
    }

    /*val originOffset = when (polarAngleZero) {
        PolarAngleZero.THREE_OCLOCK -> 0.0
        PolarAngleZero.SIX_OCLOCK -> PI / 2.0
        PolarAngleZero.NINE_OCLOCK -> PI
        PolarAngleZero.TWELVE_OCLOCK -> -PI / 2.0
    }*/

    // return (inputAngle.toRadians().value - PI / 2.0).toRadians()
    // return (-inputAngle.toRadians().value).toRadians()
    return (sign * inputAngle.radian + polarAngleZero.originOffset).toRadians()
}